<?php

class Gallery extends DataMapper {
	
	var $table_name	= 'galleries';
    
    var $has_one = array(
			'user' => array(			
	            'class' => 'user',
	            'other_field' => 'gallery',
	            'join_self_as' => 'gallery',
	            'join_other_as' => 'user',
	            'join_table' => 'r_galleries_users'),
    );
    
    var $validation = array(
	    'name' => array(
			'label' => 'Gallery name',
			'rules' => array('required', 'trim', 'unique_pair' => 'uid', 'alpha_dash_space', 'min_length' => 1, 'max_length' => 100),
	    ),
		'description' => array(
            'label' => 'Description',
            'rules' => array('required', 'trim', '_alpha_space_slash_dot', 'min_length' => 1, 'max_length' => 2000),
		),
		'published' => array(
            'label' => 'Published',
            'rules' => array('always_run', 'boolean'),
		),
    );
    
    function _alpha_space($field)
    {
    	return ( ! preg_match('/^([a-z ])+$/i', $field)) ? FALSE : TRUE;
    }
    
	function _alpha_space_dash_dot($field)
    {
    	return ( ! preg_match('/^([\.-a-z0-9_- ])+$/i', $field)) ? FALSE : TRUE;
    }
    
    function _alpha_space_slash_dot($field)
    {
    	return ( ! preg_match('/^([\./-a-z0-9_- ])+$/i', $field)) ? FALSE : TRUE;
    }
    
    function _integer($field)
    {
    	return ( ! preg_match('/^([0-9])+$/i', $field)) ? FALSE : TRUE;
    }
    
    function _alpha($field)
    {
    	return ( ! preg_match('/^([a-zA-Z])+$/i', $field)) ? FALSE : TRUE;
    }
	
}

/* End of file gallery.php */
/* Location: ./application/models/gallery.php */